module App::Controller
    class Edit < ItemForm
        slots :accept

        def initialize(parentitem)
            super()

            @item = parentitem
            @e = App::View::Edit.new @item
            connect_signals @e
        end

        def dispose
            @e.dispose
            super()
        end

        private
        def accept
            case @item
            when App::Items::Task
                @item.description = @e.line.text
                ts1 = @e.start.dateTime.toTime_t
                ts2 = @e.stop.dateTime.toTime_t
                #puts "ts1: #{Time.at ts1} ts2: #{Time.at ts2}"
                @item.start_ms = ts1 * 1000
                @item.stop_ms = ts2 * 1000
                @item.duration = @e.getDuration
            when App::Items::Project
                @item.name = @e.line.text
            when App::Items::Client
                @item.name = @e.line.text
            end
            @item.save

            @e.close
        end
    end
end
